<%@ page language="java" pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>

<%
	String path = request.getContextPath();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
  <head>
    <html:base />
    
    <title>selectVillage.jsp</title>
	<link href="./css/xtab.css" rel="stylesheet" type="text/css" />
 

  </head>
  
  <body>
  <html:form action="/village.do">
  <html:hidden property="method" value="village.do?method=selectVillage" />
  <table cellspacing="0" width="100%" align="center" border="1" onkeydown="keyDown(event);">

			<tr>
				<td class="tableTitle">
					小区名
				</td>
				<td>
					<html:text property="village.villageName"></html:text>
				</td>
				<td class="tableTitle">
					描述
				</td>
				<td>
					<html:text property="village.remark"></html:text>
				</td>
			</tr>
			 
			<tr>
				<td colspan="4" align="center">
					<input type="button" class="button" id="search" value="搜 索">
					<input type="button" class="button" id="clear" value="清 空">
				</td>
			</tr>
		</table>
		 
  <table align="center" width="100%" cellspacing="0">
			<tr>
				<th class="tableTitle">
					 <input type="checkbox" name="allVillage" onclick="checkAll('village');">
				</th>
				<th class="tableTitle">
					小区名
				</th>
				<th class="tableTitle">
					小区电话
				</th>
                <th class="tableTitle">
					描述
				</th>
			 
			</tr>
			<logic:iterate id="s" name="pageBean" property="list" indexId="index">
				<tr>
					<td class="tableElement">
						<input type="checkbox" name="village" value="${s.villageId }">
						<input type="hidden" id="villageName_${index }" value="${s.villageName }">
					</td>
				
					<td class="tableElement">
						${s.villageName }
					</td>
					<td class="tableElement">
						${s.telephone }
					</td>
					<td class="tableElement">
						${s.remark }
					</td>
				</tr>
			</logic:iterate>
		</table>
		<br>
		<jsp:include page="../common/pagtion.jsp"></jsp:include>
   <div align="center">
    <input type="button" value="确 定" class="button" name="ok" onclick="comfirmSelect();">
     <input type="button" value="取消" class="button" name="cancel" onclick="cancelSelect();">
     </div>
    <script>
     
      function comfirmSelect(){
      
        var strId="";
          var strName="";
           var roomids = document.getElementsByName("village");  
           for (var j = 0; j < roomids.length; j++) {
              if(roomids.item(j).checked == true){  
              	   strId+=roomids.item(j).value+",";
              	   strName+=document.getElementById("villageName_"+j).value+",";
              }   
          }
          if(strName==""){
          	alert("请至少选择一项");
          	return false;
          }else{
           	window.opener.document.getElementById("villageName").value=strName.substring(0,strName.length-1);
        	window.opener.document.getElementById("village").value=strId.substring(0,strId.length-1);
      		window.close();
          } 
       
      }
      function cancelSelect(){
      	window.close();
      }
      
       
	$("#search").click(function(){
		var f=document.forms[0];
		f.action="village.do?method=selectVillage";
		f.submit();
	}); 
	
	function keyDown(event){
	    if(event.keyCode==13)
	    {
			$("#search").click();
			//event.returnValue=false; 
		}
	}
	
	$("#clear").click(function(){
		 document.getElementById("village.villageName").value="";
		  document.getElementById("village.remark").value="";
	}); 
	
	function checkAll(formvalue) {  
            var roomids = document.getElementsByName(formvalue);  
           for (var j = 0; j < roomids.length; j++) {
              if(document.getElementsByName('allVillage')[0].checked==true){
              	roomids.item(j).checked = true;  
              }   
              else{
              	roomids.item(j).checked = false;  
              }   
          }  
        }
    </script>
    </html:form>
  </body>
</html:html>
